package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.kaishengit.entity.File;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class FileDao {
	
	private DBHelp<File> db = new DBHelp<File>();
	
	public void Save (String id,String name,String type,String filesize,String createtime,String t_folder_id,String t_employee_id) {
		String sql = "insert into t_file(id,name,type,filesize,createtime,t_folder_id,t_employee_id) values(?,?,?,?,?,?,?)";
		db.executeSQL(sql, id,name,type,filesize,createtime,t_folder_id,t_employee_id);
	}

	public List<File> FindByFolder (String t_folder_id) {
		String sql = "select id,name,type,filesize,createtime,t_employee_id from t_file where t_folder_id = ?";
		return db.executeQueryForList(sql, new FileRowMapper(),t_folder_id);
	} 
	
	public List<File> FindAll () {
		String sql = "select id,name,type,filesize,createtime,t_folder_id,t_employee_id from t_file";
		return db.executeQueryForList(sql, new FileRowMapper());
	}
	
	private class FileRowMapper implements RowMapper<File> {
		
		public File mapperRow (ResultSet rs) throws SQLException {
			
			File file = new File();
			file.setId(rs.getString("id"));
			file.setName(rs.getString("name"));
			file.setType(rs.getString("type"));
			file.setFilesize(rs.getString("filesize"));
			file.setCreatetime(rs.getString("createtime"));
			file.setT_folder_id(rs.getString("t_folder_id"));
			file.setT_employee_id(rs.getString("t_employee_id"));
			return file;
		}
	}
}
